<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<div id="parent">
    parent
    <div id="child">child</div>
    <input type="text" id="child2">
</div>
<script>
    var parent = document.getElementById('parent');
    var child = document.getElementById('child');
    var child2 = document.getElementById('child2');
    parent.onclick = function(){
        alert('我是父元素点击');
    }
    child.onclick = function(){
        var e = window.event || arguments[0];
        if (e.stopPropagation) {
            e.stopPropagation();
        } else {
            e.cancelBubble = true;
        }
        alert('我是子元素点击');
    }
    child2.onfocus = function(){
        alert('我是子元素移入焦点');
    }
</script>
</body>
</html>